<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <div class="flex">
      <el-card shadow="never" class="mt10 left" :body-style="{ padding: '0px' }" style="flex-shrink: 0; background-color: #eeeeee; width: 300px">
        <!-- 员工建档 -->
        <el-card shadow="never" :body-style="{ padding: '10px' }">
          <h1 class="f16">员工建档</h1>
          <div class="flex mt15">
            <el-button class="primaryBth" type="primary" size="default" @click="newUserBtn">新员工建档</el-button>
            <!-- 奖惩 -->
            <RewardAndPunishment></RewardAndPunishment>
          </div>
        </el-card>
        <!-- 离职作业 -->
        <el-card shadow="never" :body-style="{ padding: '10px 10px 15px' }" class="mt10">
          <h1 class="f16">离职作业</h1>
          <div class="mt15 leave">
            <el-form label-width="65px" :inline="true" label-position="left">
              <el-form-item label="" style="margin-right: 10px">
                <el-select style="width: 120px" v-model="leaveReason" value-key="" placeholder="离职原因" clearable filterable @change="">
                  <el-option v-for="item in leaveReasonOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-date-picker style="width: 100px" v-model="leaveDate" placeholder="离职日期" format="YYYY/MM/DD" value-format="YYYY-MM-DD">
                </el-date-picker>
              </el-form-item>
            </el-form>
            <div class="flex" style="justify-content: space-around">
              <el-button type="primary" size="default" @click="leaveBtn">离职确认</el-button>
              <el-button
                type="primary"
                size="default"
                @click="
                  () => {
                    ;(leaveDrawer = true), getTable15List()
                  }
                "
                >离职查询</el-button
              >
              <el-button
                type="primary"
                size="default"
                @click="
                  () => {
                    ;(reasonDialog = true), getTable14List()
                  }
                "
                >原因建档</el-button
              >
            </div>
          </div>
        </el-card>
        <!-- 部门异动 -->
        <el-card shadow="never" :body-style="{ padding: '10px 10px 15px' }" class="mt10">
          <h1 class="f16">部门异动</h1>
          <div class="mt15 leave">
            <el-form label-width="50px" :inline="true" label-position="left">
              <el-form-item label="" style="margin-right: 10px">
                <el-tree-select
                  placeholder="新部门"
                  v-model="newDepart"
                  :data="treeData"
                  :props="defaultProps"
                  check-strictly
                  :render-after-expand="false"
                  style="width: 200px"
                  @node-click="handleNodeClick"
                />
              </el-form-item>
            </el-form>
            <div class="flex" style="justify-content: space-around">
              <el-button class="mr5" type="primary" size="default" @click="AbnormalMovementBtn">异动确认</el-button>
              <el-button
                type="primary"
                size="default"
                @click="
                  () => {
                    ;(departDrawer = true), getTableList13()
                  }
                "
                >部门异动查询</el-button
              >
            </div>
          </div>
        </el-card>
        <!-- 职务变更 -->
        <el-card shadow="never" :body-style="{ padding: '10px 10px 0' }" class="mt10">
          <h1 class="f16">职务变更</h1>
          <div class="mt15 leave">
            <el-form label-width="50px" :inline="true" label-position="left">
              <el-form-item style="margin-right: 10px">
                <el-select style="width: 90px" v-model="newDep" value-key="" placeholder="新职务" clearable filterable @change="">
                  <el-option v-for="item in workOption" :key="item.optionValue" :label="item.optionLabel" :value="item.optionValue"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-button class="mr5" type="primary" size="default" @click="workChangeBtn">变更确认</el-button>
              </el-form-item>
              <el-form-item label="">
                <el-button
                  type="primary"
                  size="default"
                  @click="
                    () => {
                      ;(changeDrawer = true), getTableList16()
                    }
                  "
                  >变更查询</el-button
                >
              </el-form-item>
            </el-form>
          </div>
        </el-card>
        <!-- 工种变更 -->
        <el-card shadow="never" :body-style="{ padding: '10px 10px 15px' }" class="mt10">
          <h1 class="f16">工种变更</h1>
          <div class="mt15 leave">
            <el-form label-width="60px" :inline="true" label-position="left">
              <el-form-item label="" style="margin-right: 5px">
                <el-select style="width: 90px" v-model="newWorkType" value-key="" placeholder="新工种" clearable filterable @change="">
                  <el-option v-for="item in workTypeOption" :key="item.optionValue" :label="item.optionLabel" :value="item.optionValue"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="">
                <el-date-picker style="width: 100px" v-model="workTypeDate" placeholder="变更日期" format="YYYY/MM/DD" value-format="YYYY-MM-DD">
                </el-date-picker>
              </el-form-item>
            </el-form>
            <div class="flex" style="justify-content: space-around">
              <el-button type="primary" size="default" @click="workTypeBtn">变更确认</el-button>
              <el-button
                type="primary"
                size="default"
                @click="
                  () => {
                    ;(workTypeDrawer = true), getTableList17()
                  }
                "
                >工种变更查询</el-button
              >
            </div>
          </div>
        </el-card>
        <!-- 银行卡信息变更 -->
        <el-card shadow="never" :body-style="{ padding: '10px 10px 15px' }" class="mt10">
          <h1 class="f16">银行卡信息变更</h1>
          <div class="mt15 leave flex">
            <el-input style="width: 115px" class="mr10" v-model="bankUserName" placeholder="开户名" clearable @change=""></el-input>
            <el-input v-model="bankName" placeholder="开户行" clearable @change=""></el-input>
          </div>
          <div class="flex mt10 AIC">
            <el-input class="mr10" v-model="bankNumber" placeholder="银行卡号" clearable @change=""></el-input>
            <el-button type="primary" size="default" @click="bankChangeBtn">变更确认</el-button>
            <el-button
              type="primary"
              size="default"
              @click="
                () => {
                  ;(bankDrawer = true), getTableList18()
                }
              "
              >变更查询</el-button
            >
          </div>
        </el-card>
        <!-- 导出作业
      <el-card shadow="never" :body-style="{ padding: '10px' }" class="mt10">
        <h1 class="f16">导出作业</h1>
        <div class="flex mt10 AIC JCC">
          <el-button type="primary" size="default" @click="">花名册导出</el-button>
        </div>
      </el-card> -->
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '10px' }" class="mt10 ml10">
        <div class="flex">
          <h1 class="f16">员工资料明细</h1>
          <JDialog
            :tableHeader="tableHeader10"
            :width="73"
            :currentTableRow="currentTableRow"
            @confirm="confirm"
            :unAdd="true"
            :unSub="true"
            :unEdit="false"
            :getOptionList="getOptionList"
          />
        </div>
        <Table
          class="mt10"
          :tableData="tableData"
          :tableHeader="tableHeader"
          :selection="true"
          :isLoading="isLoading"
          @selectList="selectTableList"
          @currentRow="currentRow"
        />
        <PageModule :PageData="{ total, buttonS: true }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
      </el-card>
    </div>

    <!-- 新员工建档抽屉 -->
    <el-drawer v-model="drawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList10" @findClicked="findClicked10" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-tree accordion style="max-width: 600px; min-width: 170px" :data="treeData" :props="defaultProps" @node-click="handleNodeClick2" />
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <div class="flex">
              <h1 class="f16">待确认员工资料明细</h1>
              <JDialog
                :tableHeader="tableHeader10"
                :width="73"
                @removeOne="removeOne"
                :currentTableRow="currentTable10Row"
                @confirm="confirm10"
                :unEdit="false"
                :unAdd="true"
                :getOptionList="getOptionList"
              />
            </div>
            <Table :tableHeader="tableHeader10" :tableData="tableData10" class="mt10" :outTableHeight="150" @currentRow="currentRow10" />
            <PageModule :PageData="{ total: total15, buttonS: true }" @pageSizeChange="handleSizeChange15" @pageChange="handleCurrentChange15" />
          </el-card>
        </div>
      </div>
    </el-drawer>
    <!-- 抽屉中的职务建档 -->
    <el-dialog title="职务建档" v-model="workAddDialog" width="23%" draggable>
      <div style="margin-top: -35px">
        <Find :OriginalFilter="{ static: true }" :formList="formList11" @findClicked="findClicked11" :searchImg="false" />

        <Table :tableHeader="tableHeader11" :tableData="tableData11" class="mt10" :outTableHeight="150" @currentRow="currentRow11" />
      </div>
    </el-dialog>

    <!-- 工种建档Dialog -->
    <el-dialog title="工种建档" v-model="workTypeDialog" width="23%" draggable>
      <div style="margin-top: -35px">
        <Find :OriginalFilter="{ static: true }" :formList="formList12" @findClicked="findClicked12" :searchImg="false" />

        <Table :tableHeader="tableHeader12" :tableData="tableData12" class="mt10" :outTableHeight="150" @currentRow="currentRow12" />
      </div>
    </el-dialog>

    <!-- 部门异动查询 -->
    <el-drawer v-model="departDrawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList13" @findClicked="findClicked13" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <h1 class="f16">员工部门异动资料明细</h1>
            <Table :tableHeader="tableHeader13" :tableData="tableData13" class="mt10" :outTableHeight="150" :isLoading="isLoading13" />
            <PageModule :PageData="{ total: total13, buttonS: true }" @pageSizeChange="handleSizeChange13" @pageChange="handleCurrentChange13" />
          </el-card>
        </div>
      </div>
    </el-drawer>

    <!-- 离职作业：原因建档 -->
    <el-dialog title="原因建档" v-model="reasonDialog" width="23%" draggable>
      <div style="margin-top: -35px">
        <Find :OriginalFilter="{ static: true }" :formList="formList14" @findClicked="findClicked14" :searchImg="false" />
        <h1 class="f16 mt10">离职原因</h1>
        <Table :tableHeader="tableHeader14" :tableData="tableData14" class="mt10" :outTableHeight="150" @currentRow="currentRow14" />
      </div>
    </el-dialog>
    <!-- 离职作业：离职查询 -->
    <el-drawer v-model="leaveDrawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList15" @findClicked="findClicked15" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <h1 class="f16">员工离职资料明细</h1>
            <Table
              :tableHeader="tableHeader15"
              :tableData="tableData15"
              class="mt10"
              :outTableHeight="150"
              :isLoading="isLoading15"
              @currentRow="currentRow15"
            />
            <PageModule :PageData="{ total: total15, buttonS: true }" @pageSizeChange="handleSizeChange15" @pageChange="handleCurrentChange15" />
          </el-card>
        </div>
      </div>
    </el-drawer>

    <!-- 职务变更 -->
    <el-drawer v-model="changeDrawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList16" @findClicked="findClicked16" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <h1 class="f16">员工职务变更资料明细</h1>
            <Table :tableHeader="tableHeader16" :tableData="tableData16" class="mt10" :outTableHeight="150" :isLoading="isLoading16" />
            <PageModule :PageData="{ total: total16, buttonS: true }" @pageSizeChange="handleSizeChange16" @pageChange="handleCurrentChange16" />
          </el-card>
        </div>
      </div>
    </el-drawer>

    <!-- 工种变更 -->
    <el-drawer v-model="workTypeDrawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList17" @findClicked="findClicked17" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <h1 class="f16">员工工种变更资料明细</h1>
            <Table :tableHeader="tableHeader17" :tableData="tableData17" class="mt10" :outTableHeight="150" :isLoading="isLoading17" />
            <PageModule :PageData="{ total: total17, buttonS: true }" @pageSizeChange="handleSizeChange17" @pageChange="handleCurrentChange17" />
          </el-card>
        </div>
      </div>
    </el-drawer>

    <!-- 银行卡信息变更查询 -->
    <el-drawer v-model="bankDrawer" :direction="'ttb'" size="small" :with-header="false">
      <span @click="drawer = false" style="float: right; cursor: pointer; color: rgb(7, 7, 7)">X</span>
      <div class="flex AIC" style="flex-direction: column">
        <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList18" @findClicked="findClicked18" />
        <div class="flex mt10 JCC" style="width: 100%; background-color: white">
          <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }">
            <h1 class="f16">银行卡信息变更资料查询</h1>
            <Table :tableHeader="tableHeader18" :tableData="tableData18" class="mt10" :outTableHeight="150" :isLoading="isLoading18" />
            <PageModule :PageData="{ total: total18, buttonS: true }" @pageSizeChange="handleSizeChange18" @pageChange="handleCurrentChange18" />
          </el-card>
        </div>
      </div>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import LoginWork from '@/utils/LoginWork'
import fileRequest from '@/utils/fileRequest'
import { formateData } from '@/plugins/mixinJ'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'EmployeeDataOperation'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { computed, ref } from 'vue'
import { ElMessage } from 'element-plus'
import service from '@/utils/request'
import { debounce } from 'lodash'
import { onMounted, watch } from 'vue'
import RewardAndPunishment from './components/RewardAndPunishment.vue'
const workAddDialog = ref(false)
const RewardAndPunishmentIsShow = ref(false)
const departDrawer = ref(false)
const newDepart = ref('')
const workTypeDialog = ref(false)
const treeData = ref([]) as any
const defaultProps = {
  value: 'deptNo',
  children: 'childDepartment',
  label: 'deptName'
}
const currentTreeNode = ref()
const handleNodeClick = (data: any) => {
  currentTreeNode.value = JSON.parse(JSON.stringify(data))
}
const leaveReason = ref('')
const leaveReasonOptions = ref([]) as any
const leaveDate = ref('')
const workOption = ref([]) as any
const workTypeOption = ref([]) as any
const formList = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '部门',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '进厂日期',
    dateValue: ''
  },
  {
    type: 'date',
    dateLabel: '出生日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入开户名',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入开户行',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入银行卡号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '合同签订',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '已签',
        optionLabel: '已签'
      },
      {
        optionKey: '2',
        optionValue: '未签',
        optionLabel: '未签'
      }
    ]
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  // {
  //   type: 'button',
  //   checkboxLabel: '工种建档'
  // },
  {
    type: 'button',
    checkboxLabel: '花名册导出'
  }
])

const tableHeader = ref([
  {
    width: 70,
    change: true,
    label: '部门名称',
    prop: 'deptName'
  },
  {
    width: 70,
    change: true,
    label: '工号',
    prop: 'workerId'
  },
  {
    width: 50,
    label: '姓名',
    prop: 'name'
  },
  {
    width: 50,
    label: '性别',
    prop: 'sex'
  },
  {
    width: 130,
    label: '身份证号',
    prop: 'idNo'
  },
  {
    type: 'dateSingle2',
    label: '出生日期',
    prop: 'brisday'
  },
  {
    width: 50,
    label: '职务',
    prop: 'position'
  },
  {
    label: '工种',
    prop: 'workType'
  },
  {
    width: 60,
    label: '计时/计件',
    prop: 'calcType'
  },
  {
    width: 80,
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    width: 250,
    label: '原地址',
    prop: 'address'
  },
  {
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    width: 60,
    label: '卡号用户',
    prop: 'bankCardUser'
  },
  {
    width: 70,
    label: '开户行',
    prop: 'bankCardName'
  },
  {
    width: 120,
    label: '银行卡号',
    prop: 'bankCardId'
  },
  {
    width: 60,
    label: '合同签订',
    prop: 'contract'
  },
  {
    width: 50,
    label: '学历',
    prop: 'education'
  },
  {
    width: 50,
    label: '民族',
    prop: 'nation'
  },
  {
    label: '婚否',
    prop: 'married'
  },
  {
    label: '紧急联络人',
    prop: 'contactPerson'
  },
  {
    label: '紧急联络电话',
    prop: 'contactPhone'
  },
  {
    label: '现地址',
    prop: 'addressNow'
  },
  {
    label: '未成年',
    prop: 'childFlag'
  }
])
// 表一模块
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
      item.treeValue = ''
    })
  }
  if (content === '工种建档') {
    workTypeDialog.value = true
    getTable12List()
  }
  if (content === '花名册导出') {
    getDeptName(
      formList.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')?.treeValue
    )
    const res = (await fileRequest.post(`/Employee/exportPcEmployee2`, {
      address: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
      )?.inputValue,
      bankCardId: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入银行卡号'
      )?.inputValue,
      bankCardName: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户行'
      )?.inputValue,
      bankCardUser: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户名'
      )?.inputValue,
      calcType: formList.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时'
      )?.selectValue,
      contract: formList.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '合同签订'
      )?.selectValue,
      deptName: arr,
      idNo: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
      )?.inputValue,
      inBirthday: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出生日期'
      )?.dateValue?.[0],
      inTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期')
        ?.dateValue?.[0],
      name: formList.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
      )?.inputValue,
      outBirthday: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出生日期'
      )?.dateValue?.[1],
      outTime: formList.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期'
      )?.dateValue?.[1],
      position: formList.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '职务'
      )?.selectValue,
      sex: formList.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
        ?.selectValue,
      workType: formList.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '工种'
      )?.selectValue,
      pageNum: currentPage.value,
      pageSize: pageSize.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`filename=`)[1])
    link.download = FileName //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
}
const tableData = ref([])
const imgList = ref([])
const isLoading = ref(true)
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
let obj = {} as any
const getCurrentDeptName = (treeNode: any, treeData: any) => {
  treeData.forEach((item: any) => {
    if (item.deptNo === treeNode) {
      obj = item
    }
    if (item.childDepartment && item.childDepartment.length > 0) {
      getCurrentDeptName(treeNode, item.childDepartment)
    }
  })
}
let arr = [] as any
const getDeptNameList = (treeData: any) => {
  if (treeData.deptNo) arr.push(treeData.deptName)
  if (treeData.childDepartment && treeData.childDepartment.length > 0) {
    treeData.childDepartment.forEach((item: any) => {
      getDeptNameList(item)
    })
  }
}
const getDeptName = (treeNode: any) => {
  obj = {}
  getCurrentDeptName(treeNode, treeData.value)
  arr = []
  getDeptNameList(obj)
  console.log(arr)
  return arr
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  getDeptName(
    formList.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')?.treeValue
  )
  let tableDataList = await service.post<any, any>('/Employee/getEmployeeInformationDetails', {
    address: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
    )?.inputValue,
    bankCardId: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入银行卡号'
    )?.inputValue,
    bankCardName: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户行'
    )?.inputValue,
    bankCardUser: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户名'
    )?.inputValue,
    calcType: formList.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时'
    )?.selectValue,
    contract: formList.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '合同签订'
    )?.selectValue,
    deptName: arr,
    idNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    inBirthday: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出生日期'
    )?.dateValue?.[0],
    inTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期')
      ?.dateValue?.[0],
    name: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    outBirthday: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '出生日期'
    )?.dateValue?.[1],
    outTime: formList.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期')
      ?.dateValue?.[1],
    position: formList.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '职务')
      ?.selectValue,
    sex: formList.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    workType: formList.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '工种')
      ?.selectValue,
    pageNum: currentPage.value,
    pageSize: pageSize.value
  })
  isLoading.value = false
  imgList.value = tableDataList.list.map((item: any) => {
    return item.photoPath
  })
  tableData.value = tableDataList.list
  total.value = tableDataList.total
  currentRow()
}, 500)
// 点击表给另一张表传数据
const currentTableRow = ref({}) as any
const currentRow = async (row: any = tableData.value[0] ? tableData.value[0] : {}) => {
  currentTableRow.value = row
}
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked, item.treeValue
    }),
  () => {
    getTableList()
  }
)

// 新员工建档抽屉
const newUserBtn = () => {
  drawer.value = true
  getDrawerList()
}
onMounted(() => {
  getTreeData()
})
// 奖惩资料建档抽屉
const rewardBtn = () => {
  RewardAndPunishmentIsShow.value = true
}

const age = computed(() => {
  const age = calculateAge(
    formList10.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '身份证号'
    )?.inputValue
  )
  return age
})
const formList10 = ref([
  {
    inputDisabled: true,
    type: 'input',
    inputPlaceholder: '部门代码',
    inputValue: ''
  },
  // {
  //   inputDisabled: true,
  //   type: 'input',
  //   inputPlaceholder: '工号',
  //   inputValue: ''
  // },
  {
    type: 'input',
    inputPlaceholder: '姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '身份证号',
    inputValue: ''
  },
  {
    inputDisabled: true,
    type: 'input',
    inputPlaceholder: '年龄',
    inputValue: age
  },
  {
    type: 'dateSingle',
    dateLabel: '生日',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '职务',
    selectOptions: workOption
  },
  {
    allowCreate: 'N',
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'input',
    inputPlaceholder: '电话号码',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    inputDisabled: true,
    type: 'input',
    inputPlaceholder: '部门名称',
    inputValue: ''
  },
  {
    type: 'dateSingle',
    dateLabel: '进厂日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '合同签订',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '已签',
        optionLabel: '已签'
      },
      {
        optionKey: '2',
        optionValue: '未签',
        optionLabel: '未签'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '学历',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '民族',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '婚否',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '已婚',
        optionLabel: '已婚'
      },
      {
        optionKey: '2',
        optionValue: '未婚',
        optionLabel: '未婚'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '紧急联络人',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '紧急联络电话',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '现地址',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '未成年标志',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '是',
        optionLabel: '是'
      },
      {
        optionKey: '2',
        optionValue: '否',
        optionLabel: '否'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入开户名',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入开户行',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入银行卡号',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '插入员工资料'
  },
  {
    type: 'button',
    checkboxLabel: '确认员工资料'
  },
  {
    type: 'button',
    checkboxLabel: '职务建档'
  }
]) as any
const drawer = ref(false)
const findClicked10 = async (content: string) => {
  if (content === '职务建档') {
    workAddDialog.value = true
    getTable11List()
  }
  if (content === '置空') {
    formList10.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '插入员工资料') {
    console.log(age.value)
    if (
      !formList10.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期')
        ?.dateValue
    ) {
      JMessage.error('请选择进厂日期')
      return
    }
    const res = (await LoginWork.post('/Employee/getPcEmployeeAdd', {
      address: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
      )?.inputValue,
      addressNow: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '现地址'
      )?.inputValue,
      bankCardId: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入银行卡号'
      )?.inputValue,
      bankCardName: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户行'
      )?.inputValue,
      bankCardUser: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入开户名'
      )?.inputValue,
      calcType: formList10.value.find(
        (item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时'
      )?.selectValue,
      childFlag:
        formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '未成年标志')
          ?.selectValue === '是'
          ? 'N'
          : 'Y',
      contactPerson: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '紧急联络人'
      )?.inputValue,
      contactPhone: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '紧急联络电话'
      )?.inputValue,
      contract: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '合同签订')
        ?.selectValue,
      dateIn:
        formList10.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '进厂日期')
          ?.dateValue + ' 00:00:00',
      deptName: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部门名称'
      )?.inputValue,
      deptNo: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部门代码'
      )?.inputValue,
      education: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '学历'
      )?.inputValue,
      idNo: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '身份证号'
      )?.inputValue,
      married:
        formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '婚否')
          ?.selectValue === '已婚'
          ? 'Y'
          : 'N',
      mobileNo: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '电话号码'
      )?.inputValue,
      name: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '姓名'
      )?.inputValue,
      nation: formList10.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '民族'
      )?.inputValue,
      position: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '职务')
        ?.selectValue,
      sex: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
        ?.selectValue,
      workType: formList10.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工种')
        ?.selectValue,
      brisday: formList10.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '生日')
        ?.dateValue
        ? formList10.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '生日')
            ?.dateValue + ' 00:00:00'
        : ''
    })) as any
    if (res.code === 200) {
      JMessage.success('插入成功')
      getDrawerList()
    } else if (res.code === 504) {
      JMessage.error(res.message)
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '确认员工资料') {
    const idNo = currentTable10Row.value.idNo
    const res = (await LoginWork.post(`/Employee/getConfirmEmployeeInformation?idNo=${idNo}`)) as any
    if (res.code === 200) {
      JMessage.success('确认成功')
      getDrawerList()
    } else {
      JMessage.error(res.message)
    }
  }
}
const workOptionJ = ref([])
const workTypeOptionJ = ref([])
const tableHeader10 = ref([
  {
    type: 'treeJ',
    label: '部门名称',
    prop: 'deptName',
    treeData: treeData,
    defaultProps: defaultProps
  },
  {
    change: true,
    label: '工号',
    prop: 'workerId'
  },
  {
    label: '姓名',
    prop: 'name'
  },
  {
    type: 'selectJ',
    label: '性别',
    prop: 'sex',
    options: [
      {
        value: '男',
        label: '男'
      },
      {
        value: '女',
        label: '女'
      }
    ]
  },
  {
    width: 150,
    change: true,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    type: 'selectJ',
    label: '职务',
    prop: 'position',
    options: workOptionJ
  },
  {
    type: 'selectJ',
    label: '工种',
    prop: 'workType',
    options: workTypeOptionJ
  },
  {
    type: 'selectJ',
    label: '计时/计件',
    prop: 'calcType',
    options: [
      {
        value: '计件',
        label: '计件'
      },
      {
        value: '计时',
        label: '计时'
      }
    ]
  },
  {
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    label: '地址',
    prop: 'address'
  },
  {
    type: 'dateSingle2',
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '开户姓名',
    prop: 'bankCardUser'
  },
  {
    change: true,
    label: '开户行',
    prop: 'bankCardName'
  },
  {
    change: true,
    label: '银行卡号',
    prop: 'bankCardId'
  },
  {
    type: 'selectJ',
    label: '合同签订',
    prop: 'contract',
    options: [
      {
        value: '已签',
        label: '已签'
      },
      {
        value: '未签',
        label: '未签'
      }
    ]
  },
  {
    change: true,
    label: '学历',
    prop: 'education'
  },
  {
    // change: true,
    label: '民族',
    prop: 'nation'
  },
  {
    type: 'selectJ',
    // change: true,
    label: '婚否',
    prop: 'married',
    options: [
      {
        value: '已婚',
        label: '已婚'
      },
      {
        value: '未婚',
        label: '未婚'
      }
    ]
  },
  {
    label: '紧急联络人',
    prop: 'contactPerson'
  },
  {
    label: '紧急联络电话',
    prop: 'contactPhone'
  },
  {
    // change: true,
    label: '现地址',
    prop: 'addressNow'
  },
  {
    type: 'selectJ',
    change: true,
    label: '未成年',
    prop: 'childFlag',
    options: [
      {
        value: '是',
        label: '是'
      },
      {
        value: '否',
        label: '否'
      }
    ]
  }
])
const tableData10 = ref([])
const getDrawerList = async () => {
  const res = await LoginWork.get('/Employee/getConfirmedEmployeeInformationDetails')
  tableData10.value = res.data
  currentRow10()
}
const selectedLists10 = ref([])
const selectTableList10 = (selectedList: any) => {
  selectedLists10.value = selectedList
}
const currentTable10Row = ref({}) as any
const currentRow10 = async (row: any = tableData10.value[0]) => {
  currentTable10Row.value = row
  // let table10Data = await service.post<any, any>(`/Outgoing/getNumberDetailsList`, row)
  // tableData10.value = table10Data
}
// Dialog确认添加/修改按钮
const confirm = async (obj: any, dialogVisible: any, title: any) => {
  // 向服务器发送请求，更新外派单信息
  if (title === '修改') {
    const res = (await LoginWork.put(`/Employee/getEmployeeInformationUpdate`, {
      ...obj,
      calcType: obj.calcType.value ? obj.calcType.value : '',
      brisday: obj.brisday ? obj.brisday + ' 00:00:00' : '',
      dateIn: obj.dateIn ? obj.dateIn + ' 00:00:00' : '',
      childFlag: obj.childFlag === '是' ? 'N' : 'Y',
      workType: obj.workType.value,
      married: obj.married === '已婚' ? 'Y' : 'N',
      sex: obj.sex ? obj.sex.value : '',
      updateStatus: 1
    })) as any
    // 判断请求是否成功
    if (res.code === 200) {
      JMessage.success(res.message)
      getTableList()
    } else {
      JMessage.error(res.message)
    }
  }
  // 关闭弹出框
  dialogVisible.value = false
  // 重新获取表格数据
  getDrawerList()
}
const confirm10 = async (obj: any, dialogVisible: any, title: any) => {
  // 向服务器发送请求，更新外派单信息
  if (title === '修改') {
    const res = (await LoginWork.put(`/Employee/getConfirmedEmployeeInformationDetailsUpdate`, {
      ...obj,
      calcType: obj.calcType.value ? obj.calcType.value : '',
      dateIn: obj.dateIn ? obj.dateIn + ' 00:00:00' : '',
      childFlag: obj.childFlag === '是' ? 'N' : 'Y',
      married: obj.married === '已婚' ? 'Y' : 'N',
      workType: obj.workType.value ? obj.workType.value : '',
      sex: obj.sex ? obj.sex.value : ''
    })) as any
    // 判断请求是否成功
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.error(res.message)
    }
  }
  // 关闭弹出框
  dialogVisible.value = false
  // 重新获取表格数据
  getTableList()
}
// 删除
const removeOne = async () => {
  const { idNo } = currentTable10Row.value
  // 向服务器发送请求，更新外派单信息
  const res = (await LoginWork.post(`/Employee/getConfirmedEmployeeInformationDetailsDel?idNo=${idNo}`)) as any
  // 判断请求是否成功
  if (res.code === 200) {
    JMessage.success(res.message)
  } else {
    JMessage.error(res.message)
  }
  // 重新获取表格数据
  getDrawerList()
}
// 树
// 获取数据
const getTreeData = async () => {
  const res = (await LoginWork.get('/dept/GetAllData')) as any
  treeData.value = res.data
}
const currentTreeNode2 = ref()
const handleNodeClick2 = (data: any) => {
  currentTreeNode2.value = JSON.parse(JSON.stringify(data))
  formList10.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部门代码'
  ).inputValue = data.deptNo
  formList10.value.find(
    (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '部门名称'
  ).inputValue = data.deptName
}

// 获取职务下拉框
const getWorkOptions = async () => {
  const res = await LoginWork.get('/Employee/getDutiesList')
  workOption.value = res.data.map((item: any) => {
    return {
      optionKey: item.positionSeq,
      optionValue: item.position,
      optionLabel: item.position
    }
  })
}
const getWorkOptionsJ = async () => {
  const res = await LoginWork.get('/Employee/getDutiesList')
  workOptionJ.value = res.data.map((item: any) => {
    return {
      value: item.position,
      label: item.position
    }
  })
}
// 获取工种下拉框
const getWorkTypeOptions = async () => {
  const res = (await LoginWork.post('/Employee/getWorkTypeList', {
    pageNum: 1,
    pageSize: 9999,
    workType: ''
  })) as any
  workTypeOption.value = res.data.list.map((item: any) => {
    return {
      optionKey: item.workTypeSeq,
      optionValue: item.workType,
      LeftLabel: item.workType,
      RightLabel: item.workTypeSeq
    }
  })
}
const getWorkTypeOptionsJ = async () => {
  const res = (await LoginWork.post('/Employee/getWorkTypeList', {
    pageNum: 1,
    pageSize: 9999,
    workType: ''
  })) as any
  workTypeOptionJ.value = res.data.list.map((item: any) => {
    return {
      value: item.workType,
      label: item.workType
    }
  })
}
const getOptionList = () => {
  getWorkOptionsJ()
  getWorkTypeOptionsJ()
}
onMounted(() => {
  getWorkOptions()
  getWorkTypeOptions()
})

// 职务建档
const tableData11 = ref([])
const tableHeader11 = ref([
  {
    label: '序号',
    prop: 'positionSeq'
  },
  {
    label: '职务',
    prop: 'position'
  }
])
const getTable11List = async () => {
  const res = await LoginWork.get('/Employee/getDutiesList')
  tableData11.value = res.data
}
const formList11 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入职务',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '插入'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])
// 点击表给另一张表传数据
const currentTable11Row = ref({}) as any
const currentRow11 = async (row: any = tableData.value[0]) => {
  currentTable11Row.value = row
}
const findClicked11 = async (content: string) => {
  if (content === '插入') {
    const res = (await LoginWork.post('/Employee/getDutiesAdd', {
      position: formList11.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入职务'
      )?.inputValue
      // "positionSeq": tableData11.value.length,
    })) as any
    if (res.code === 200) {
      JMessage.success('添加成功')
      getTable11List()
      getWorkTypeOptions()
      getWorkTypeOptionsJ()
    } else {
      JMessage.error('添加失败')
    }
  }
  if (content === '删除') {
    const { positionSeq } = currentTable11Row.value
    const res = (await LoginWork.post(`/Employee/getDutiesDel?positionSeq=${positionSeq}`)) as any
    if (res.code === 200) {
      JMessage.success('删除成功')
      getTable11List()
      getWorkTypeOptions()
      getWorkTypeOptionsJ()
    } else {
      JMessage.error('删除失败')
    }
  }
}
watch(formList11.value, () => {
  getTable11List()
})

// 工种建档
const tableData12 = ref([])
const tableHeader12 = ref([
  {
    label: '序号',
    prop: 'workTypeSeq'
  },
  {
    label: '工种',
    prop: 'workType'
  },
  {
    label: '基本工资',
    prop: 'workTypeSalary'
  }
])
const getTable12List = async () => {
  const res = await LoginWork.post('/Employee/getWorkTypeList', {
    pageNum: 1,
    pageSize: 9999,
    workType: formList12.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工种'
    )?.inputValue
  })
  tableData12.value = res.data.list
}
const formList12 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入工种',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入工资',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '插入'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])
// 点击表给另一张表传数据
const currentTable12Row = ref({}) as any
const currentRow12 = async (row: any = tableData.value[0]) => {
  currentTable12Row.value = row
}
const findClicked12 = async (content: string) => {
  if (content === '插入') {
    const res = (await LoginWork.post('/Employee/getWorkTypeAdd', {
      workType: formList12.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工种'
      )?.inputValue,
      workTypeSalary: formList12.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入工资'
      )?.inputValue
    })) as any
    if (res.code === 200) {
      JMessage.success('添加成功')
      getTable12List()
      getWorkOptions()
      getWorkOptionsJ()
    } else {
      JMessage.error('添加失败')
    }
  }
  if (content === '删除') {
    const res = (await LoginWork.post(`/Employee/getWorkTypeDel?workTypeSeq=${currentTable12Row.value.workTypeSeq}`)) as any
    if (res.code === 200) {
      JMessage.success('删除成功')
      getTable12List()
      getWorkOptions()
      getWorkOptionsJ()
    } else {
      JMessage.error(res.message)
    }
  }
}
watch(formList12.value, () => {
  getTable12List()
})

// 部门异动查询抽屉
const formList13 = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '异动前部门',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '异动日期',
    dateValue: ''
  },
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '新部门',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const findClicked13 = (content: string) => {
  if (content === '置空') {
    formList13.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableHeader13 = ref([
  {
    change: true,
    label: '异动日期',
    prop: 'sysDate'
  },
  {
    change: true,
    label: '异动后部门',
    prop: 'change'
  },
  {
    change: true,
    label: '异动前部门',
    prop: 'deptName'
  },
  {
    change: true,
    label: '姓名',
    prop: 'name'
  },
  {
    change: true,
    label: '性别',
    prop: 'sex'
  },
  {
    change: true,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    change: true,
    label: '职务',
    prop: 'position'
  },
  {
    change: true,
    label: '工种',
    prop: 'workType'
  },
  {
    change: true,
    label: '计时/计件',
    prop: 'calcType'
  },
  {
    change: true,
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    change: true,
    label: '地址',
    prop: 'address'
  },
  {
    change: true,
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '合同签订',
    prop: 'contract'
  }
])
const tableData13 = ref([])
const imgList13 = ref([])
const isLoading13 = ref(true)
// 分页器
const currentPage13 = ref(1)
const pageSize13 = ref(40)
const total13 = ref(0)
const handleSizeChange13 = (val: number) => {
  pageSize13.value = val
  getTableList13()
}
const handleCurrentChange13 = (val: number) => {
  currentPage13.value = val
  getTableList13()
}
// 获取表数据
const getTableList13 = debounce(async () => {
  isLoading13.value = true
  let tableDataList = await service.post<any, any>('/Employee/ConfirmationOfChangesList', {
    address: formList13.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
    )?.inputValue,
    calcType: formList13.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时')
      ?.selectValue,
    deptName: getDeptName(
      formList13.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '异动前部门')
        ?.treeValue
    ),
    idNo: formList13.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    inTime: formList13.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '异动日期')
      ?.dateValue?.[0],
    name: formList13.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    newDeptName: getDeptName(
      formList13.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '新部门')
        ?.treeValue
    ),
    outTime: formList13.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '异动日期'
    )?.dateValue?.[1],
    position: formList13.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '职务')
      ?.selectValue,
    sex: formList13.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    workType: formList13.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工种')
      ?.selectValue,
    pageNum: currentPage13.value,
    pageSize: pageSize13.value
  })
  isLoading13.value = false
  imgList13.value = tableDataList.list.map((item: any) => {
    return item.photoPath
  })
  tableData13.value = tableDataList.list
  total13.value = tableDataList.total
  // currentRow13()
}, 500)
watch(formList13.value, () => {
  getTableList13()
})
const selectedLists = ref([])
const selectTableList = (selectedList: any) => {
  selectedLists.value = selectedList
}
// 异动确认按钮
const AbnormalMovementBtn = async () => {
  const res = (await LoginWork.post('/Employee/ConfirmationOfChanges', {
    ...currentTreeNode.value,
    workerIdList: selectedLists.value.map((item: any) => item.workerId)
  })) as any
  if (res.code === 200) {
    JMessage.success('异动确认成功')
    getTableList()
    newDepart.value = ''
  } else {
    JMessage.error(res.message)
  }
}

// 离职作业：原因建档
const reasonDialog = ref(false)
const formList14 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入离职原因',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '插入'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
]) as any
const tableData14 = ref([])
const tableHeader14 = ref([
  {
    label: '序号',
    prop: 'delSeq'
  },
  {
    label: '离职原因',
    prop: 'delReason'
  }
])
const getTable14List = async () => {
  const res = await LoginWork.get('/Employee/getReasonFilingList')
  tableData14.value = res.data
}
// 点击表给另一张表传数据
const currentTable14Row = ref({}) as any
const currentRow14 = async (row: any = tableData.value[0]) => {
  currentTable14Row.value = row
}
const findClicked14 = async (content: string) => {
  if (content === '插入') {
    const res = (await LoginWork.post('/Employee/getReasonFilingAdd', {
      delReason: formList14.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入离职原因'
      )?.inputValue,
      delSeq: tableData14.value.length + 1
    })) as any
    if (res.code === 200) {
      JMessage.success('添加成功')
      formList14.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入离职原因'
      ).inputValue = ''
      getTable14List()
      getLeaveReasonOptions()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '删除') {
    const res = (await LoginWork.post(`/Employee/getReasonFilingDel?delReason=${currentTable14Row.value.delReason}`)) as any
    if (res.code === 200) {
      JMessage.success('删除成功')
      getTable14List()
      getLeaveReasonOptions()
    } else {
      JMessage.error(res.message)
    }
  }
}

// 离职作业：离职查询
const leaveDrawer = ref(false)
const formList15 = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '部门',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '离职日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入离职原因',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '还原'
  },
  {
    type: 'button',
    checkboxLabel: '导出'
  }
])
const isLoading15 = ref(false)
const tableHeader15 = ref([
  {
    change: true,
    label: '离职日期',
    prop: 'sysDate'
  },
  {
    change: true,
    label: '离职原因',
    prop: 'change'
  },
  {
    change: true,
    label: '部门名称',
    prop: 'deptName'
  },
  {
    change: true,
    label: '姓名',
    prop: 'name'
  },
  {
    change: true,
    label: '性别',
    prop: 'sex'
  },
  {
    change: true,
    width: 200,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    change: true,
    label: '职务',
    prop: 'position'
  },
  {
    change: true,
    width: 100,
    label: '工种',
    prop: 'workType'
  },
  {
    change: true,
    label: '计时/记件',
    prop: 'calcType'
  },
  {
    change: true,
    width: 120,
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    change: true,
    width: 300,
    label: '地址',
    prop: 'address'
  },
  {
    change: true,
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '合同签订',
    prop: 'contract'
  }
])
const tableData15 = ref([])
// 分页器
const currentPage15 = ref(1)
const pageSize15 = ref(40)
const total15 = ref(0)
const handleSizeChange15 = (val: number) => {
  pageSize15.value = val
  getTable15List()
}
const handleCurrentChange15 = (val: number) => {
  currentPage15.value = val
  getTable15List()
}
const getTable15List = async () => {
  getDeptName(
    formList15.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')?.treeValue
  )
  isLoading15.value = true
  const res = (await service.post('/Employee/ConfirmationOfResignationList', {
    deptName: arr,
    name: formList15.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    sex: formList15.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    idNo: formList15.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    position: formList15.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '职务'
    )?.selectValue,
    workType: formList15.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '工种'
    )?.selectValue,
    calcType: formList15.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时'
    )?.selectValue,
    inTime: formList15.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期')
      ?.dateValue?.[0],
    outTime: formList15.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期'
    )?.dateValue?.[1],
    change: formList15.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入离职原因'
    )?.inputValue,
    address: formList15.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
    )?.inputValue,
    pageNum: currentPage15.value,
    pageSize: pageSize15.value
  })) as any
  isLoading15.value = false
  tableData15.value = res.list
  total15.value = res.total
}
watch(formList15.value, () => {
  getTable15List()
})
// 点击表给另一张表传数据
const currentTableRow15 = ref({}) as any
const currentRow15 = async (row: any = tableData.value[0]) => {
  currentTableRow15.value = row
}
const findClicked15 = async (content: string) => {
  if (content === '置空') {
    formList15.value.forEach((item: any) => {
      item.treeValue = ''
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '还原') {
    const res = (await LoginWork.post(`/Employee/ConfirmationOfResignationReduction?idNo=${currentTableRow15.value.idNo}`)) as any
    if (res.code === 200) {
      JMessage.success('还原成功')
      getTable15List()
    } else {
      JMessage.error(res.message)
    }
  }
  if (content === '导出') {
    getDeptName(
      formList.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门')?.treeValue
    )
    const res = (await fileRequest.post(`/Employee/ExportResignationAssignment`, {
      deptName: arr,
      name: formList15.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
      )?.inputValue,
      sex: formList15.value.find((item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
        ?.selectValue,
      idNo: formList15.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
      )?.inputValue,
      position: formList15.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '职务'
      )?.selectValue,
      workType: formList15.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '工种'
      )?.selectValue,
      calcType: formList15.value.find(
        (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时'
      )?.selectValue,
      inTime: formList15.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期'
      )?.dateValue?.[0],
      outTime: formList15.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '离职日期'
      )?.dateValue?.[1],
      change: formList15.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入离职原因'
      )?.inputValue,
      address: formList15.value.find(
        (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
      )?.inputValue,
      pageNum: currentPage15.value,
      pageSize: pageSize15.value
    })) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    link.download = `${res.headers['content-disposition'].split(' ')[1].split('=')[1]}` //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)

    // if (res.code === 200) {
    //   JMessage.success('导出成功')
    //   getTable15List()
    // } else {
    //   JMessage.error(res.message)
    // }
  }
}
// 离职确认按钮
const leaveBtn = async () => {
  const res = (await LoginWork.post('/Employee/ConfirmationOfResignation', {
    delReason: leaveReason.value.split(' ')[0],
    delDate: leaveDate.value + ' 00:00:00',
    workerIdList: selectedLists.value.map((item: any) => item.workerId)
  })) as any
  if (res.code === 200) {
    JMessage.success('离职确认成功')
    getTableList()
    leaveReason.value = ''
    leaveDate.value = ''
  } else {
    JMessage.error(res.message)
  }
}

// 职务变更查询
const changeDrawer = ref(false)
const formList16 = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '部门名称',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '变更前职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '变更日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '新职务',
    selectOptions: workOption
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const findClicked16 = (content: string) => {
  if (content === '置空') {
    formList16.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableHeader16 = ref([
  {
    change: true,
    label: '变更日期',
    prop: 'sysDate'
  },
  {
    change: true,
    label: '变更后职务',
    prop: 'change'
  },
  {
    change: true,
    label: '部门名称',
    prop: 'deptName'
  },
  {
    change: true,
    label: '姓名',
    prop: 'name'
  },
  {
    change: true,
    label: '性别',
    prop: 'sex'
  },
  {
    change: true,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    change: true,
    label: '变更前职务',
    prop: 'position'
  },
  {
    change: true,
    label: '工种',
    prop: 'workType'
  },
  {
    change: true,
    label: '计时/计件',
    prop: 'calcType'
  },
  {
    change: true,
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    width: 300,
    change: true,
    label: '地址',
    prop: 'address'
  },
  {
    change: true,
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '合同签订',
    prop: 'contract'
  }
])
const tableData16 = ref([])
const imgList16 = ref([])
const isLoading16 = ref(true)
// 分页器
const currentPage16 = ref(1)
const pageSize16 = ref(40)
const total16 = ref(0)
const handleSizeChange16 = (val: number) => {
  pageSize16.value = val
  getTableList16()
}
const handleCurrentChange16 = (val: number) => {
  currentPage16.value = val
  getTableList16()
}
// 获取表数据
const getTableList16 = debounce(async () => {
  getDeptName(
    formList16.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门名称')
      ?.treeValue
  )
  isLoading16.value = true
  let tableDataList = await service.post<any, any>('/Employee/ChangeOfPositionList', {
    address: formList16.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
    )?.inputValue,
    calcType: formList16.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时')
      ?.selectValue,
    deptName: arr,
    idNo: formList16.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    inTime: formList16.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期')
      ?.dateValue?.[0],
    name: formList16.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    change: formList16.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '新职务')
      ?.selectValue,
    outTime: formList16.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期'
    )?.dateValue?.[1],
    position: formList16.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '变更前职务')
      ?.selectValue,
    sex: formList16.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    workType: formList16.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工种')
      ?.selectValue,
    pageNum: currentPage16.value,
    pageSize: pageSize16.value
  })
  isLoading16.value = false
  tableData16.value = tableDataList.list
  total16.value = tableDataList.total
  // currentRow16()
}, 500)
watch(formList16.value, () => {
  getTableList16()
})
// 职务变更确认按钮
const newDep = ref('')
const workChangeBtn = async () => {
  const res = (await LoginWork.post('/Employee/ChangeOfPosition', {
    position: newDep.value,
    workerIdList: selectedLists.value.map((item: any) => item.workerId)
  })) as any
  if (res.code === 200) {
    JMessage.success('职务变更确认成功')
    getTableList()
    newDep.value = ''
  } else {
    JMessage.error(res.message)
  }
}

// 工种变更
const workTypeDate = ref('')
const workTypeDrawer = ref(false)
const formList17 = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '部门名称',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '变更前工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '变更日期',
    dateValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '新工种',
    selectOptions: workTypeOption
  },
  {
    type: 'input',
    inputPlaceholder: '请输入地址',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const findClicked17 = (content: string) => {
  if (content === '置空') {
    formList17.value.forEach((item: any) => {
      item.treeValue = ''
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableHeader17 = ref([
  {
    change: true,
    label: '变更日期',
    prop: 'sysDate'
  },
  {
    change: true,
    label: '变更后工种',
    prop: 'change'
  },
  {
    width: 200,
    change: true,
    label: '变更过后工资类型',
    prop: 'calcType'
  },
  {
    change: true,
    label: '部门名称',
    prop: 'deptName'
  },
  {
    change: true,
    label: '姓名',
    prop: 'name'
  },
  {
    change: true,
    label: '性别',
    prop: 'sex'
  },
  {
    width: 300,
    change: true,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    change: true,
    label: '职务',
    prop: 'position'
  },
  {
    change: true,
    label: '变更前工种',
    prop: 'workType'
  },
  {
    width: 200,
    change: true,
    label: '变更前工资类型',
    prop: 'calcType'
  },
  {
    change: true,
    label: '变更前底薪',
    prop: 'oldBasicSalary'
  },
  {
    width: 300,
    change: true,
    label: '地址',
    prop: 'address'
  },
  {
    change: true,
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '合同签订',
    prop: 'contract'
  }
])
const tableData17 = ref([])
const imgList17 = ref([])
const isLoading17 = ref(true)
// 分页器
const currentPage17 = ref(1)
const pageSize17 = ref(40)
const total17 = ref(0)
const handleSizeChange17 = (val: number) => {
  pageSize17.value = val
  getTableList17()
}
const handleCurrentChange17 = (val: number) => {
  currentPage17.value = val
  getTableList17()
}
// 获取表数据
const getTableList17 = debounce(async () => {
  getDeptName(
    formList17.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门名称')
      ?.treeValue
  )
  isLoading17.value = true
  let tableDataList = (await service.post<any, any>('/Employee/JobTypeChangeList', {
    address: formList17.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入地址'
    )?.inputValue,
    calcType: formList17.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时')
      ?.selectValue,
    deptName: arr,
    idNo: formList17.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    inTime: formList17.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期')
      ?.dateValue?.[0],
    name: formList17.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    change: formList17.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '新工种')
      ?.selectValue,
    outTime: formList17.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期'
    )?.dateValue?.[1],
    pageNum: currentPage17.value,
    pageSize: pageSize17.value,
    position: formList17.value.find(
      (item: any) => item.selectLabel && Jzhcn.Find[item.selectLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '职务'
    )?.selectValue,
    sex: formList17.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    workType: formList17.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '变更前工种')
      ?.selectValue
  })) as any
  isLoading17.value = false
  tableData17.value = tableDataList.list
  total17.value = tableDataList.total
  // currentRow17()
}, 500)
watch(formList17.value, () => {
  getTableList17()
})
const newWorkType = ref('')
const workTypeBtn = async () => {
  const res = (await LoginWork.post('/Employee/JobTypeChange', {
    workType: newWorkType.value,
    sysDate: workTypeDate.value + ' 00:00:00',
    workerIdList: selectedLists.value.map((item: any) => item.workerId)
  })) as any
  if (res.code === 200) {
    JMessage.success('工种变更确认成功')
    getTableList()
    newWorkType.value = ''
    workTypeDate.value = ''
  } else {
    JMessage.error(res.message)
  }
}

// 银行卡信息变更查询
const bankDrawer = ref(false)
// const workTypeDate = ref('')
// const workTypeDrawer = ref(false)
const formList18 = ref([
  {
    type: 'tree',
    treeValue: '',
    treeLabel: '部门名称',
    defaultProps: defaultProps,
    treeData: treeData
  },
  {
    type: 'input',
    inputPlaceholder: '请输入姓名',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '性别',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '男',
        optionLabel: '男'
      },
      {
        optionKey: '2',
        optionValue: '女',
        optionLabel: '女'
      }
    ]
  },
  {
    type: 'input',
    inputPlaceholder: '请输入身份证号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '职务',
    selectOptions: workOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '工种',
    selectOptions: workTypeOption
  },
  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectP: '计件/计时',
    selectOptions: [
      {
        optionKey: '1',
        optionValue: '计件',
        optionLabel: '计件'
      },
      {
        optionKey: '2',
        optionValue: '计时',
        optionLabel: '计时'
      }
    ]
  },
  {
    type: 'date',
    dateLabel: '变更日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入变更前信息',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  }
])
const findClicked18 = (content: string) => {
  if (content === '置空') {
    formList18.value.forEach((item: any) => {
      item.treeValue = ''
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
}
const tableHeader18 = ref([
  {
    change: true,
    label: '变更日期',
    prop: 'sysDate'
  },
  {
    width: 300,
    change: true,
    label: '变更后信息',
    prop: 'change'
  },
  {
    change: true,
    label: '部门名称',
    prop: 'deptName'
  },
  {
    change: true,
    label: '姓名',
    prop: 'name'
  },
  {
    width: 50,
    change: true,
    label: '性别',
    prop: 'sex'
  },
  {
    width: 250,
    change: true,
    label: '身份证号码',
    prop: 'idNo'
  },
  {
    change: true,
    label: '职务',
    prop: 'position'
  },
  {
    change: true,
    label: '工种',
    prop: 'workType'
  },
  {
    width: 100,
    change: true,
    label: '计时/计件',
    prop: 'calcType'
  },
  {
    width: 200,
    change: true,
    label: '电话号码',
    prop: 'mobileNo'
  },
  {
    width: 300,
    change: true,
    label: '变更前信息',
    prop: 'address'
  },
  {
    change: true,
    label: '进厂日期',
    prop: 'dateIn'
  },
  {
    change: true,
    label: '合同签订',
    prop: 'contract'
  }
])
const tableData18 = ref([])
const isLoading18 = ref(true)
// 分页器
const currentPage18 = ref(1)
const pageSize18 = ref(40)
const total18 = ref(0)
const handleSizeChange18 = (val: number) => {
  pageSize18.value = val
  getTableList18()
}
const handleCurrentChange18 = (val: number) => {
  currentPage18.value = val
  getTableList18()
}
// 获取表数据
const getTableList18 = debounce(async () => {
  getDeptName(
    formList18.value.find((item: any) => item.treeLabel && Jzhcn.Find[item.treeLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '部门名称')
      ?.treeValue
  )
  isLoading18.value = true
  let tableDataList = (await service.post<any, any>('/Employee/BankCardChangeList', {
    calcType: formList18.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '计件/计时')
      ?.selectValue,
    deptName: arr,
    idNo: formList18.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入身份证号'
    )?.inputValue,
    inTime: formList18.value.find((item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期')
      ?.dateValue?.[0],
    name: formList18.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入姓名'
    )?.inputValue,
    change: formList18.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '新工种')
      ?.selectValue,
    outTime: formList18.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '变更日期'
    )?.dateValue?.[1],
    pageNum: currentPage18.value,
    pageSize: pageSize18.value,
    position: formList18.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '职务')
      ?.selectValue,
    sex: formList18.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '性别')
      ?.selectValue,
    workType: formList18.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '工种')
      ?.selectValue,
    address: formList18.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入变更前信息'
    )?.inputValue
  })) as any
  isLoading18.value = false
  tableData18.value = tableDataList.list
  total18.value = tableDataList.total
  // currentRow18()
}, 500)
watch(formList18.value, () => {
  getTableList18()
})
const bankUserName = ref('') // 开户名
const bankName = ref('') // 开户行
const bankNumber = ref('') // 银行卡号
const bankChangeBtn = async () => {
  const res = (await LoginWork.post('/Employee/BankCardChange', {
    bankCardId: bankNumber.value,
    bankCardName: bankName.value,
    bankCardUser: bankUserName.value,
    workerIdList: selectedLists.value.map((item: any) => item.workerId)
  })) as any
  if (res.code === 200) {
    JMessage.success('银行卡变更成功')
    getTableList()
    bankUserName.value = ''
    bankName.value = ''
    bankNumber.value = ''
  } else {
    JMessage.error(res.message)
  }
}

// 计算年龄
function calculateAge(idCard: any) {
  if (!idCard) return 0
  const birthdayStr = idCard.substring(6, 14) // 身份证上出生日期的位置为6至14
  const birthYear = parseInt(birthdayStr.substring(0, 4))
  const birthMonth = parseInt(birthdayStr.substring(4, 6))
  const birthDay = parseInt(birthdayStr.substring(6, 8))

  const today = new Date()
  const currentYear = today.getFullYear()
  const currentMonth = today.getMonth() + 1
  const currentDay = today.getDate()

  let age = currentYear - birthYear

  if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
    age-- // 还未过生日，年龄减一
  }

  return age
}
// 获取离职原因下拉框
const getLeaveReasonOptions = async () => {
  const res = (await LoginWork.get('/Employee/getReasonFilingList')) as any
  if (res.code === 200) {
    leaveReasonOptions.value = res.data.map((item: any) => {
      return {
        value: `${item.delReason}  ${item.delSeq}`,
        label: `${item.delReason}`
      }
    })
  }
}
onMounted(() => {
  getLeaveReasonOptions()
})
</script>

<style lang="less" scoped>
:deep(.el-dialog__body) {
  padding: 0px 20px 10px !important;
}

.leave {
  :deep(.el-form--inline .el-form-item) {
    margin-right: 0px;
  }
}

.left {
  :deep(.el-input__wrapper) {
    height: 27px;
  }

  :deep(.el-form-item__label) {
    padding: 0px;
  }

  :deep(button) {
    height: 23px;
  }
}

:deep(.is-disabled) {
  width: 150px;
}
</style>
